﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKRevitCode.ElmentSearchUtility.LinkDocumentSuite;
using YJKRGeometry;
using SectionSignAndFilled.StairsRoomSection.DataDefine;
using SectionSignAndFilled.StairsRoomSection.Kit;

namespace SectionSignAndFilled.StairsRoomSection.ElementPacket
{
	internal class LayerObject : ElementObject
	{
		public LayerObject(BaseLinkDocumentResultBean LinkElem, SectionViewData secviewData = null) : base(LinkElem, secviewData)
		{
			this.m_objectType = ObjectType.kLayerType;
		}

		public Curve GetLastLayerCutCurve(int index, double dElevator)
		{
			Wall wall = base.SelfElem.UseElement as Wall;
			double num = 0.0;
			bool flag = false;
			if (index >= 0)
			{
				using (List<ElementObject>.Enumerator enumerator = base.LstChildObj.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						ElementObject elementObject = enumerator.Current;
						LayerObject layerObject = elementObject as LayerObject;
						if (layerObject.m_IndexPos == index)
						{
							num += layerObject.m_dWidth;
							flag = true;
							break;
						}
						num += layerObject.m_dWidth;
					}
					goto IL_8D;
				}
			}
			num = 0.0;
			flag = true;
			IL_8D:
			if (!flag)
			{
				return null;
			}
			Curve curve = (wall.Location as LocationCurve).Curve;
			double width = wall.Width;
			double num2 = width / 2.0 - num;
			Curve curve2;
			if (curve is Arc)
			{
				Arc arc = curve as Arc;
				double radius = arc.Radius;
				XYZ center = arc.Center;
				double num3 = 0.0;
				double num4 = 0.0;
				Geometry.GetArcAngles(arc, ref num3, ref num4);
				curve2 = Arc.Create(new XYZ(center.X, center.Y, dElevator), radius + num2, num3, num4, XYZ.BasisX, XYZ.BasisY);
				Transaction transaction = new Transaction(wall.Document, "t1");
				transaction.Start();
				wall.Document.Create.NewDetailCurve(wall.Document.ActiveView, curve2);
				transaction.Commit();
			}
			else
			{
				Line line = curve as Line;
				XYZ endPoint = line.GetEndPoint(0);
				XYZ endPoint2 = line.GetEndPoint(1);
				XYZ direction = line.Direction;
				XYZ xyz = XYZ.Zero;
				XYZ xyz2 = Geometry.RotateTo(direction, Math.PI*.5, XYZ.BasisZ);
				if (xyz2.IsAlmostEqualTo(wall.Orientation))
				{
					xyz = xyz2 * num2;
				}
				else
				{
					xyz = xyz2 * -num2;
				}
				XYZ xyz3 = endPoint + xyz;
				XYZ xyz4 = endPoint2 + xyz;
				curve2 = Line.CreateBound(new XYZ(xyz3.X, xyz3.Y, dElevator), new XYZ(xyz4.X, xyz4.Y, dElevator));
			}
			return curve2;
		}

		public int m_IndexPos;

		public double m_dWidth;

		public XYZ m_Normal = new XYZ(0.0, 0.0, 1.0);

		public int m_MaxLayerIndex;

		public int m_MinLayerIndex;

		public ElementObject m_parentObj;
	}
}
